﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace Logistics_Service
{
    public class DataProvider
    {
        public static string connect_string = @"Data Source=LAPTOP-WIN7;Initial Catalog=VanChuyen;Integrated Security=True";
        public static SqlConnection connect = new SqlConnection();
        public static SqlCommand cmd = new SqlCommand();

        public DataProvider()
        {
            connect.ConnectionString = connect_string;
        }

        public void Open()
        {
            try
            {
                connect.ConnectionString = connect_string;
                connect.Open();
            }
            catch (Exception)
            {
            }
        }

        public void Close()
        {
            connect.Close();
        }

        public DataTable ExecuteQuery(string sql)
        {
            Open();
            DataTable tb = new DataTable();
            cmd = connect.CreateCommand();
            cmd.CommandText = sql;
            SqlDataAdapter adp = new SqlDataAdapter();
            adp.SelectCommand = cmd;
            adp.Fill(tb);
            Close();
            return tb;
        }

        public bool ExecuteNonQuery(string sql)
        {
            Open();
            try
            {
                cmd = connect.CreateCommand();
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();
                Close();
                return true;
            }
            catch (Exception)
            {
                Close();
                return false;
            }
        }
    }
}